<?php

/**
 * This is the model class for table "kota".
 *
 * The followings are the available columns in table 'kota':
 * @property integer $ID_KOTA
 * @property integer $ID_PROVINSI
 * @property string $NAMA_KOTA
 *
 * The followings are the available model relations:
 * @property DetailPerjalananBus[] $detailPerjalananBuses
 * @property DetailPerjalananBus[] $detailPerjalananBuses1
 * @property DetailPerjalananKereta[] $detailPerjalananKeretas
 * @property DetailPerjalananKereta[] $detailPerjalananKeretas1
 * @property DetailPerjalananTravel[] $detailPerjalananTravels
 * @property DetailPerjalananTravel[] $detailPerjalananTravels1
 * @property Provinsi $iDPROVINSI
 * @property Pemberhentian[] $pemberhentians
 */
class Kota extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Kota the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'kota';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('NAMA_KOTA', 'required'),
			array('ID_PROVINSI', 'numerical', 'integerOnly'=>true),
			array('NAMA_KOTA', 'length', 'max'=>20),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_KOTA, ID_PROVINSI, NAMA_KOTA', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'detailPerjalananBuses' => array(self::HAS_MANY, 'DetailPerjalananBus', 'ID_KOTA'),
			'detailPerjalananBuses1' => array(self::HAS_MANY, 'DetailPerjalananBus', 'KOT_ID_KOTA'),
			'detailPerjalananKeretas' => array(self::HAS_MANY, 'DetailPerjalananKereta', 'KOT_ID_KOTA'),
			'detailPerjalananKeretas1' => array(self::HAS_MANY, 'DetailPerjalananKereta', 'ID_KOTA'),
			'detailPerjalananTravels' => array(self::HAS_MANY, 'DetailPerjalananTravel', 'KOT_ID_KOTA'),
			'detailPerjalananTravels1' => array(self::HAS_MANY, 'DetailPerjalananTravel', 'ID_KOTA'),
			'iDPROVINSI' => array(self::BELONGS_TO, 'Provinsi', 'ID_PROVINSI'),
			'pemberhentians' => array(self::HAS_MANY, 'Pemberhentian', 'ID_KOTA'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_KOTA' => 'Id Kota',
			'ID_PROVINSI' => 'Id Provinsi',
			'NAMA_KOTA' => 'Nama Kota',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_KOTA',$this->ID_KOTA);
		$criteria->compare('ID_PROVINSI',$this->ID_PROVINSI);
		$criteria->compare('NAMA_KOTA',$this->NAMA_KOTA,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}